import cv2
import numpy as np
if __name__ == '__main__':
    image_np = cv2.imread('work2.jpg')
    angle = 317
    scale = 0.8
    M = cv2.getRotationMatrix2D((1308, 1935), angle, scale)
    rotation_image = cv2.warpAffine(image_np, M, (image_np.shape[1], image_np.shape[0]), flags = cv2.INTER_LANCZOS4, borderMode= cv2.BORDER_WRAP)

    x_min, x_max = 480, 985
    y_min, y_max = 48, 396

    ROI_image = rotation_image.copy()[y_min:y_max, x_min:x_max]
    line_width = 2
    cv2.rectangle(rotation_image, (x_min, y_min), (x_max, y_max), (0, 0, 255), line_width)

    # cv2.imshow('', rotation_image)
    cv2.imshow('', ROI_image)
    cv2.imwrite('zuoye2.jpg', ROI_image)
    cv2.waitKey(0)
